import fs from "fs";
import formidable from "formidable";

// export function saveFile(path, file){
//     fs.writeFile(path, file,(err)=>{
//         if (err){
//             console.log("存储失败" + err)
//         }else {
//             console.log("存储成功")
//         }
//     })
// }

export async function saveFile(path, req){
    const form = formidable({
        multiples: true,
        uploadDir: path, // 自定义临时文件夹路径
        maxTotalFileSize: 10 * 1024 * 1024 * 1024,
        maxFileSize: 5 * 1024 * 1024 * 1024
    })
    const [fields, files] = await form.parse(req);

    return {
        files,
        fields
    }
}

